#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QKeySequence>
#include <QMap>
#include <QAbstractNativeEventFilter>
#include <QPointer>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE


class QMyNativeEventFilter : public QAbstractNativeEventFilter
{
public:
    explicit QMyNativeEventFilter(QWidget *parent = nullptr);
    virtual ~QMyNativeEventFilter();

    void setWidget(QWidget *w);
protected:
    virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *result);
private:
    QPointer<QWidget> m_widget;
};

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void onApplyButtonClicked();
private:
    int registerHotkey(const QKeySequence& ks);
private:
    Ui::MainWindow *ui;

    QMyNativeEventFilter m_filter;
    QMap<int, QKeySequence> m_hotkeys;
};
#endif // MAINWINDOW_H
